#include <STC89C5xRC.H>

unsigned long beats = 0;

void StartMotor(unsigned long angle);

void main()
{
	TMOD = 0x01;
	TL0 = 0xCD;
	TH0 = 0xF8;
	TR0 = 1;
	ET0 = 1;
	EA = 1;
	
	StartMotor(180);
	while(1);
}
void StartMotor(unsigned long angle)
{
	EA = 0;
	beats = (angle * 4096) / 360;
	EA = 1;
}

void Timer0_Isr(void) interrupt 1
{	
	unsigned char code BeatCode[8] = {0xE,0xC,0xD,0x9,0xB,0x3,0x7,0x6};
	static unsigned char index = 0;
	unsigned char temp;
	
	TL0 = 0xCD;
	TH0 = 0xF8;
	if(beats != 0)
	{
		temp = P1;
		temp &= 0xF0;
		temp = temp | BeatCode[index];
		P1 = temp;
		index++;
		index %= 8;
		beats--;
	}
	else
	{
		P1 = P1 | 0x0F;
	}
}


